export default {
  data() {
    return {
      expandAll: false,
    };
  },
  methods: {
    // 期望时间格式 09：14 06：30
    filterDate(time) {
      if (!time) {
        return '';
      }
      const TWO = 2;
      // ios时间需要用 / 代替-
      const fixIosDate = time.replace(/\-/g, '/');
      const date = new Date(fixIosDate);
      // 取到每天的凌晨1点来区分日期
      const dayBeforeLastday = new Date();
      dayBeforeLastday.setDate(dayBeforeLastday.getDate() - TWO);
      dayBeforeLastday.setHours(1);
      const lastDay = new Date();
      lastDay.setDate(lastDay.getDate() - 1);
      lastDay.setHours(1);
      const now = new Date();
      now.setHours(1);
      let dateText;
      if (date < dayBeforeLastday) {
        dateText = date
          .toLocaleDateString('zh-CN', {
            month: '2-digit',
            day: '2-digit',
          })
          .split('/')
          .join('-');
        dateText = `${dateText} `;
      } else if (date < lastDay) {
        dateText = '前天 ';
      } else if (date < now) {
        dateText = '昨天 ';
      } else {
        dateText = '';
      }
      // 從字符串中分割出時間
      const times = time.split(' ')[1];
      const res = times.split(':');
      dateText = `${dateText}${res[0]}:${res[1]}`;
      if (!this.spDate) {
        dateText = `${res[0]}:${res[1]}`;
      }
      return dateText;
    },
    // 客户端查看大图
    openImg(images, index) {
      if (!window.getAppVersion || !window.getAppVersion()) {
        //  端外不处理
        return;
      }
      const urlList = [];
      images.forEach(e => {
        urlList.push(e.url);
      });
      _t.openImg({ index, url: urlList });
    },
    expand() {
      this.expandAll = true;
    },
  },
};
